import request, { get, post, put, remove } from "@/utils/request"
import { Action, GetVO } from "./types"
import { getUrl } from "./utils/ActionUtil"

export const pageApi = async (action: Action, params = {}) => await get(getUrl(action), params)

export const saveApi = async (action: Action, data: Record<string, any>) => await post(getUrl(action), data)

export const updateApi = async (action: Action, data: Record<string, any>) => await put(getUrl(action), data)

export const removeApi = async (action: Action, id: string) => await remove(`${getUrl(action)}/${id}`)

export const detailApi = async (action: Action, id: string) => await get(`${getUrl(action)}/${id}`)

export const getApi = async (action: Action, id: string): Promise<GetVO> => await get(`${getUrl(action)}/${id}`)

export const setApi = async (action: Action, id: string, ...value: string[]) => await put(getUrl(action), {id, value: `${value}`})

export const resetApi = async (action: Action, id: string) => await put(`${getUrl(action)}?id=${id}`)

export const statApi = async (action: Action): Promise<Record<string, number>> => await get(`${getUrl(action)}`)

// export const auditApi = async (action: Action, data) => {
//   const res = await request.post(`${getUrl(action)}/${action.name}`, data)
//   return res.data
// }

// export const refreshApi = async (action: Action) => {
//   const res = await request.get(`${getUrl(action)}/${action.name}`)
//   return res.data
// }

// export const maxIdApi = async (action: Action) => {
//   const res = await request.get(`${getUrl(action)}/${action.name}`)
//   return res.data
// }

// export const incrementsApi = async (action: Action, maxId) => {
//   const res = await request.get(`${getUrl(action)}/${action.name}`, { params: { maxId }})
//   return res.data
// }

// export const updatesApi = async (action: Action) => {
//   const res = await request.get(`${getUrl(action)}/${action.name}`)
//   return res.data
// }

export const loginApi = async (action: Action, data) => {
  return await request.post(`login`, data)
}

export const profileApi = async () => {
  const res = await request.get(`profile`)
  return res.data
}

export const logoutApi = async () => {
  return await request.get(`logout`)
}

export const appApi = async () => {
  return await request.get(`app`)
}